﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'laydate', 'common', 'xmSelect', 'optimizeSelectOption'], function () {
        var form = layui.form,
            $ = layui.$,
            common = layui.common;
        wcLoading.close();
        //监听提交
        var lock = false;
        //$('#F_MaterialBatch').val(new Date().Format("yyyyMMddhhmmss") + Math.floor(Math.random() * 10));
        form.on('submit(saveBtn)', function (data) {
            if (!lock) {
                var postData = data.field;
                var index = parent.layer.load(0, {
                    shade: [0.5, '#000'], //0.1透明度的背景
                });
                lock = true;
                var tempdata = common.currentWindow().layui.table.cache.currentTableId;
                var temp = {};
                temp.F_MaterialBatch = postData.F_MaterialBatch;
                temp.F_Id = Number(new Date().Format("hhmmss") + Math.floor(Math.random() * 10));
                temp.F_Num = postData.F_Num;
                for (var i = 0; i < tempdata.length; i++) {
                    if (temp.F_MaterialBatch == tempdata[i].F_MaterialBatch) {
                        common.modalMsg("批号重复，请修改", "warning");
                        parent.layer.close(index);
                        lock = false;
                        return false;
                    }
                }
                tempdata.push(temp);
                common.modalMsg("操作成功", "success");
                common.currentWindow().layui.table.reload('currentTableId', {
                    data: tempdata
                });
                parent.layer.close(index);
                common.modalClose();
                lock = false;
            }
            return false;
        });
    });
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item">
                    <label class="layui-form-label required">批号</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_MaterialBatch" name="F_MaterialBatch" maxlength="50" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">数量</label>
                    <div class="layui-input-block">
                        <input type="number" pattern="[0-9]*" id="F_Num" name="F_Num" lay-verify="required" value="125" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>

